<?php
use Workerman\Protocols\Http;Workerman\Protocols\Http::sessionStart();
$G_MODEL_NAME = basename(__FILE__,'.js.php');
$G_MODEL_URL = $_SESSION["MES_WEB_URL"].'/'. $G_MODEL_NAME;

?>
<?php date_default_timezone_set('PRC');?>
<?php $access_token = $_SESSION["ACCESS_TOKEN"];?>


console.log("html bianxie laydate shili")
//执行一个laydate实例
laydate.render({
    elem: '#test1' //指定元素
    ,type: 'datetime'
});

//打开校稿内容
function openOriginalMapConfig(id) {

    $("#mod_body").html("");
    $.get("./modules/poster_information/mod_poster_information_management_details.php?poster_id="+id,function(result){
        $("#mod_body").html(result);
        $.getScript("./modules/poster_information/mod_poster_information_management_details.js.php?poster_id="+id,
            function() {
                $(document.body).attr("class", "pace-done mini-navbar");
                //完成 modules js load
                //newFun('"Checking new script"'); //这个函数是在new.js里面的，当点击click后运行这个函数
            });
    });

};

for (var selector in chosen_config) {
    $(selector).chosen(chosen_config[selector]);
    $(".chosen-container ").css("width","100%");
}

$('.input-daterange').datepicker({
    keyboardNavigation: false,
    todayBtn: 'linked',
    todayHighlight:true,
    forceParse: false,
    calendarWeeks: true,
    autoclose: true,
    format: 'yyyy-mm-dd',
    language: 'zh-CN'
});


////日期选择（yyyyy-mm-dd / hh-mm-ss）
//var start = {
//    elem: '#start',
//    format: 'YYYY/MM/DD hh:mm:ss',
//    min: laydate.now(), //设定最小日期为当前日期
//    max: '2099-06-16 23:59:59', //最大日期
//    istime: true,
//    istoday: false,
//    choose: function (datas) {
//       console.log(datas , "2222222222")
//    }
//};
//laydate(start)



function mod_fun_action(key){

    if(key=="add"){
        $('[name="mod_poster_information_management_input_id"]').val("");
        $('[name="mod_poster_information_management_input_name"]').val("");
        $('[name="mod_poster_information_management_input_end_time"]').val("<?php echo date('Y-m-d H:m:s',time());?>");
        $('#dlg_<?php echo $G_MODEL_NAME; ?>_form').modal('show');
        return;
    }

    if(key=="edit"){
        var o = oTable.row('.selected');
        //判断没有选中行
        if(typeof(o.data()) == "undefined"){
            return;
        }
        $('[name="mod_poster_information_management_input_id"]').val(o.data()["id"]);
        $('[name="mod_poster_information_management_input_name"]').val(o.data()["name"]);
        /*var i=0;
		$('[name="mod_poster_information_management_input_department_id"]').find("option").each(function(){
			if($(this).text() == o.data()[4]){
				$("[name='mod_poster_information_management_input_department_id']").get(0).selectedIndex=i;
			}
			i++;
		});
        $('[name="mod_poster_information_management_input_department_id"]').trigger("chosen:updated");*/
        $('[name="mod_poster_information_management_input_end_time"]').val(o.data()["end_time"]);

        $('#dlg_<?php echo $G_MODEL_NAME; ?>_form').modal('show');
        return;
    }

    if(key=="delete"){
        var o = oTable.row('.selected');
        //判断没有选中行
        if(typeof(o.data()) == "undefined"){
            return;
        }
        swal({
            title: '确定删除该记录',
            text: '如果删除该记录,数据将无法恢复!',
            type: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: '删除！',
            cancelButtonText: '取消！',
        }).then(function(result){
            if (result.value) {
                //删除当前选择行
                var id = o.data()["id"];
                ajax_request({url:"<?php echo $G_MODEL_URL;?>",type:"POST",dataType:"TEXT",data:{action:"delete",id:id},access_token:"<?php echo $access_token?>"},function(result){
                    var result = JSON.parse(result);
                    result = result["rtval"];
                    if(result=="done"){
                        //刷新数据
                        oTable.ajax.reload();
                        swal(
                            '已经删除!',
                            '该记录已被成功删除',
                            'success'
                        );
                    }else{
                        oTable.ajax.reload();
                        swal(
                            '无法删除!',
                            result,
                            'error'
                        );

                    }
                })
            }
        })
        return;
    }

    if(key=="refresh"){
        //刷新数据
        oTable.ajax.reload();
        return;
    }

    return;
}

// 订单查询
function do_order_search(){


    var tm_from = $("[name='mod_poster_information_management_datepick_from']").val();
    var tm_to = $("[name='mod_poster_information_management_datepick_to']").val();
    var order_status = $("[name='mod_poster_information_management_order_status'] option:selected").val();
    var search_data = {"action":"","tm_from":tm_from,"tm_to":tm_to,"order_status":order_status};
    oTable.clear().draw();
    ajax_request({url:"<?php echo $G_MODEL_URL;?>",type:"POST",dataType:"JSON",data:search_data,access_token:"<?php echo $access_token?>"},function(result){
        var result = result["rtval"];
        if(result['data'].length <= 0){
            swal({title: "查询失败", text: "该查询条件下，无订单数据", type: "error",confirmButtonText: "确认"});
        }else{

            oTable.rows.add(result['data']).draw();
        }
    })
}

var addSelect = true;

// 上传海报页数
function mod_poster_information_management_page(result){
    $('[name="mod_poster_information_management_page"]').empty();
    for(v in result["page_arr"]){
        var page = result["page_arr"][v];
        $('[name="mod_poster_information_management_page"]').append('<option value="' + page + '">第' + page + '页</option>');
    }
    $('[name="mod_poster_information_management_page"]').trigger("chosen:updated");
}

function get_mod_poster_information_management_page(id){
    let data = {"action":"get_page_info","poster_id":id};
    ajax_request({url:"<?php echo $G_MODEL_URL;?>",type:"POST",dataType:"JSON",data:data,access_token:"<?php echo $access_token?>"},function(result){
        let res = result["rtval"];
        // 判断返回数据是否为空，如果是则还未上传海报图片
        mod_poster_information_management_page(res);

    })
}

//上传海报图片
function do_poster_upload(id,lock , end_time ){
    if (parseInt((new Date()).getTime()/1000) > end_time){
        swal("错误","稿件已超过校稿时间，不允许上传海报","error");
        return;
    }

    get_mod_poster_information_management_page(id)




    if(lock == 1){
        swal("错误","已锁定稿件，不允许上传海报","error");
        return;
    }
    // 显示第几次校稿
    show_proofreading_times();
    $('#dlg_<?php echo $G_MODEL_NAME; ?>_poster_upload_form').modal('show');
    //初始化fileinput
    //var oFileInput = new FileInput();
    //oFileInput.Init("txt_file", '<?php echo $G_MODEL_URL;?>',id);
    $('#txt_file').fileinput('destroy');
    $('#txt_file').fileinput({
        language: 'zh', //设置语言
        uploadUrl: '<?php echo $G_MODEL_URL;?>', //上传的地址
        uploadAsync: false, //关闭异步上传，采用同步上传
        allowedFileExtensions: ['jpg', 'gif', 'png'],//接收的文件后缀
        showUpload: true, //是否显示上传按钮
        showCaption: false,//是否显示标题
        browseClass: "btn btn-primary", //按钮样式
        layoutTemplates :{
            actionZoom:'',//去除上传预览缩略图中的查看详情预览的缩略图标
        },
        dropZoneTitle:"拖拽文件到这里 &hellip;<br>只支持 .jpg, .gif, .png 格式文件",
        minFileCount: 1,

        maxFileCount: 1, //表示允许同时上传的最大文件个数

        enctype: 'multipart/form-data',
        validateInitialCount:true,
        maxFileSize: 0,//单位为kb，如果为0表示不限制文件大小

        previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
        msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大上传文件数({m})！",
        uploadExtraData:function(){
            var data = {
                "action":"upload_poster_image",
                "poster_id": id,
                "page": $("[name='mod_poster_information_management_page_number']").val(),
                "area": $("[name='mod_poster_information_management_area']").val(),
                access_token:"<?php echo $access_token?>"
            }
            return data;
        }
    }).on('fileuploaded', function(event, previewId, index, fileId) {
        console.log('File Uploaded', 'ID: ' + fileId + ', Thumb ID: ' + previewId);


    }).on('fileuploaderror', function(event, data, msg) {
        console.log('File Upload Error', 'ID: ' + data.fileId + ', Thumb ID: ' + data.previewId);
    }).on('filebatchuploadcomplete', function(event, preview, config, tags, extraData) {
        console.log('File Batch Uploaded', preview, config, tags, extraData);
        get_mod_poster_information_management_page(id);

    });/*.on("change", function() {
            // 清除掉上次上传的图片
            $(".uploadPreview").find(".file-preview-frame:first").remove();
            $(".uploadPreview").find(".kv-zoom-cache:first").remove(); 
        });*/

}




// 导入按钮页数
function mod_poster_information_management_page_btn(result){
    $('[name="mod_poster_information_management_page_btn"]').empty();
    for(v in result["page_arr"]){
        var page = result["page_arr"][v];
        $('[name="mod_poster_information_management_page_btn"]').append('<option value="' + page + '">第' + page + '页</option>');
    }
    $('[name="mod_poster_information_management_page_btn"]').trigger("chosen:updated");
}

//当前海报已上传按钮
var afterBtn = [];
function after_do_btn_upload(id){
    afterBtn = [];
    let dataBtn = {"action":"get_poster_button_number","poster_management_id":id};
    ajax_request({url:"<?php echo $G_MODEL_URL;?>",type:"POST",dataType:"JSON",data:dataBtn,access_token:"<?php echo $access_token?>"},function(result){
        for(val in result["rtval"]){
            afterBtn.push(val)
        }

        $(".after-btn-title").html("");
        afterBtn.forEach((val)=>{
            if(val == $("[name='mod_poster_information_management_page_btn']").val()){
            $(".after-btn-title").html("注：该海报已上传按钮 ， 如果重复上传会覆盖先前上传的按钮")
            }
        })

    })
}

$("#after-btn").change(function(){
    $(".after-btn-title").html("");
     afterBtn.forEach((val)=>{
         if(val == $("[name='mod_poster_information_management_page_btn']").val()){
            $(".after-btn-title").html("注：该海报已上传按钮 ， 如果重复上传会覆盖先前上传的按钮")
          }
    })

});

//上传按钮
function do_btn_upload(id,lock){

    after_do_btn_upload(id)


    
    let data = {"action":"get_page_info","poster_id":id};
    ajax_request({url:"<?php echo $G_MODEL_URL;?>",type:"POST",dataType:"JSON",data:data,access_token:"<?php echo $access_token?>"},function(result){
        let res = result["rtval"];
        // 判断返回数据是否为空，如果是则还未上传海报图片
        mod_poster_information_management_page_btn(res);
    })



    // 显示第几次校稿
    $('#dlg_<?php echo $G_MODEL_NAME; ?>_poster_upload_csv').modal('show');
    //初始化fileinput
    //var oFileInput = new FileInput();
    //oFileInput.Init("txt_file", '<?php echo $G_MODEL_URL;?>',id);
    $('#btn_file').fileinput('destroy');
    $('#btn_file').fileinput({

        uploadUrl: '<?php echo $G_MODEL_URL;?>', //上传的地址
        uploadAsync: true, //异步上传

        language: "zh",  //设置语言

        showCaption: true, //是否显示标题

        showUpload: true, //是否显示上传按钮

        showRemove: true, //是否显示移除按钮

        showPreview : true, //是否显示预览按钮

        browseClass: "btn btn-primary", //按钮样式

        dropZoneEnabled: false, //是否显示拖拽区域

        allowedFileExtensions: ["csv", "xlsx"], //接收的文件后缀

        maxFileCount: 1,  //最大上传文件数限制

        previewFileIcon: '',

        allowedPreviewTypes: null,

        uploadExtraData:function(){
            var data = {
                "action":"upload_poster_csv",
                "poster_management_id": id,
                "page": $("[name='mod_poster_information_management_page_btn']").val(),
                access_token:"<?php echo $access_token?>"
            }
            return data;
        }
    }).on('fileuploaded', function(event, previewId, index, fileId) {
        console.log('File Uploaded', 'ID: ' + fileId + ', Thumb ID: ' + previewId);
    }).on('fileuploaderror', function(event, data, msg) {
        console.log('File Upload Error', 'ID: ' + data.fileId + ', Thumb ID: ' + data.previewId);
    }).on('filebatchuploadcomplete', function(event, preview, config, tags, extraData) {
        console.log('File Batch Uploaded', preview, config, tags, extraData);
        after_do_btn_upload(id);
    });/*.on("change", function() {
            // 清除掉上次上传的图片
            $(".uploadPreview").find(".file-preview-frame:first").remove();
            $(".uploadPreview").find(".kv-zoom-cache:first").remove();
        });*/

}


//打开绑定部门modal
function do_poster_picture_department(id,lock){
    if(lock == 1){
        swal("错误","已锁定稿件，不允许绑定部门 \r 如果需要查看海报绑定部门，请点击查看按钮 ","error");
        return;
    }
    show_proofreading_times();
    var data = {"action":"get_page_info","poster_id":id};
    ajax_request({url:"<?php echo $G_MODEL_URL;?>",type:"POST",dataType:"JSON",data:data,access_token:"<?php echo $access_token?>"},function(result){
        var result = result["rtval"];
        // 判断返回数据是否为空，如果是则还未上传海报图片
        var b = $.isEmptyObject(result);
        if(b){
            swal("错误","还未上传海报图片，请先上传海报图片","error");
            return;
        }
        poster_picture_department_page(result);
        var first_page = "";
        for(var v in result["page_arr"]){
            if(first_page == ""){
                first_page = result["page_arr"][v];
            }
        }
        rendering_department_and_pictures(result["poster_contents_id"],first_page);
        $('#dlg_<?php echo $G_MODEL_NAME; ?>_poster_picture_department_form').modal('show');

    })


}

// 在上传海报modal和绑定部门modal上显示第几次校稿
function show_proofreading_times(){
    var number = oTable.row('.selected').data()["number"];
    var finish = oTable.row('.selected').data()["finish"];
    var lock = oTable.row('.selected').data()["lock"];
    // 如果finish为1，lock为0,表示上次校稿已完成
    $(".poster_number").text(number);
    if(finish == 1 && lock==0){
        $(".poster_number").text(parseInt(number)+1);
    }

}

// 绑定部门页数
function poster_picture_department_page(result){
    $('[name="mod_poster_information_management_input_poster_contents_id"]').val(result["poster_contents_id"]);
    $('[name="mod_poster_picture_department_page"]').empty();
    for(v in result["page_arr"]){
        var page = result["page_arr"][v];
        $('[name="mod_poster_picture_department_page"]').append('<option value="' + page + '">第' + page + '页</option>');
    }
    $('[name="mod_poster_picture_department_page"]').trigger("chosen:updated");
}

// 绑定部门选择页数change事件
$('[name="mod_poster_picture_department_page"]').chosen().change(function(e){
    var page =  $(this).val();
    var poster_contents_id =  $('[name="mod_poster_information_management_input_poster_contents_id"]').val();
    rendering_department_and_pictures(poster_contents_id,page);
});

// 选择部门，渲染部门绑定关系和图片信息
function rendering_department_and_pictures(poster_contents_id,page){
    var data = {"action":"get_department_and_pictures","poster_contents_id":poster_contents_id,"page":page};
    ajax_request({url:"<?php echo $G_MODEL_URL;?>",type:"POST",dataType:"JSON",data:data,access_token:"<?php echo $access_token?>"},function(result){
        var result = result["rtval"];
        var area_arr = result["area_arr"];
        var department_arr = result["department_arr"];
        var department_data = result["department_data"];
        department_binding(department_data,department_arr);

        $('[name="mod_poster_picture_department_picture_list"]').empty();
        var area_html = "";
        for(var area in area_arr){
            var area_text = area_name(area);
            var picture_id = area_arr[area]["picture_id"];
            var picture_path = area_arr[area]["picture_path"];

            area_html += '<div style="margin-bottom: 3%;" class="picture_list" picture_id="'+picture_id+'"><div class="chat-activity-list"><div class="chat-element"style="overflow: visible;height: 120px;"><a href="#"class="pull-left"><img alt="image"class="img-circle"style="width: 100px;height: 100px;border-radius: 10%;"src="./poster_images'+picture_path+'"></a><strong>'+area_text+'</strong></div></div></div>';

        }

        $('[name="mod_poster_picture_department_picture_list"]').html(area_html);

    })
}

// 部门绑定信息
function department_binding(department_data,department_arr){

    $('[name="mod_poster_picture_department_binding"]').empty();
    var department_str = "";
    for(v in department_data){
        var id = department_data[v]["id"];
        var name = department_data[v]["name"];
        if(department_arr.includes(id)){
            department_str += '<option selected value="' + id + '">' + name + '</option>';
        }else{
            department_str += '<option value="' + id + '">' + name + '</option>';
        }

    }
    $('[name="mod_poster_picture_department_binding"]').html(department_str);
    $('[name="mod_poster_picture_department_binding"]').trigger("chosen:updated");

}

// 确认绑定按钮
$('[name="btn_poster_picture_department_binding"]').click(function(){

    var action = "set_poster_picture_department";
    var picture_id = $('.picture_list').eq(0).attr("picture_id");
    var department_id = $('[name="mod_poster_picture_department_binding"]').val();
    if(department_id == null){
        swal("错误","请选择要绑定的部门","error");
        return false;
    }
    swal({
        title: '确定绑定部门?',
        type: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: '绑定！',
        cancelButtonText: '取消！',
    }).then(function(result){
        if (result.value) {
            ajax_request({url:"<?php echo $G_MODEL_URL;?>",type:"POST",dataType:"TEXT",data:{action:action,picture_id:picture_id,department_id:department_id},access_token:"<?php echo $access_token?>"},function(result){
                var result = JSON.parse(result);
                result = result["rtval"];
                if(result=="done"){
                    swal("绑定成功","部门绑定成功","success");
                    //$('#dlg_<?php //echo $G_MODEL_NAME; ?>//_poster_picture_department_form').modal('hide');
                }else{
                    swal("错误",result,"error");
                }
            })
        }
    })
    return false;
})

// 删除页按钮
$('[name="btn_poster_picture_department_delete"]').click(function(){
    var action = "delete_page_area_picture";
    var picture_id = $('.picture_list').eq(0).attr("picture_id");

    swal({
        title: '确定删除当前页?',
        text: '该页下所有版本海报将被删除，如需绑定请重新上传',
        type: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: '删除！',
        cancelButtonText: '取消！',
    }).then(function(result){
        if (result.value) {
            ajax_request({url:"<?php echo $G_MODEL_URL;?>",type:"POST",dataType:"TEXT",data:{action:action,picture_id:picture_id},access_token:"<?php echo $access_token?>"},function(result){
                var result = JSON.parse(result);
                result = result["rtval"];
                if(result=="done"){
                    swal("删除成功","该页海报已被删除","success");
                    $('#dlg_<?php echo $G_MODEL_NAME; ?>_poster_picture_department_form').modal('hide');
                }else{
                    swal("错误",result,"error");
                }
            })
        }
    })
    return false;
})

// 锁定当期稿件
function do_poster_lock(id){
    var action = "poster_lock";
    ajax_request({url:"<?php echo $G_MODEL_URL;?>",type:"POST",dataType:"TEXT",data:{action:action,poster_id:id},access_token:"<?php echo $access_token?>"},function(result){
        var result = JSON.parse(result);
        result = result["rtval"];
        if(result=="done"){
            swal("锁定成功","当次校稿已锁定，请发邮件通知采购部门校稿","success");
            oTable.ajax.reload();
        }else{
            swal("错误",result,"error");
        }
    })
}

ajax_request({url:"<?php echo $G_MODEL_URL;?>",type:"POST",dataType:"TEXT",data:{action:"get_user_data"},access_token:"<?php echo $access_token?>"} , function(res){
    localStorage.setItem("identityPC",JSON.parse(res).rtval[0].class_level);
})


//查看
function do_poster_search(id){
    if (localStorage.getItem("identityPC") == 0 || localStorage.getItem("identityPC") == 1 || localStorage.getItem("identityPC") == 2 || localStorage.getItem("identityPC") == 3){
        window.setTimeout("openOriginalMapConfig("+ id +")", 300);
    }else {
        swal("当前身份没有权限查看","","error");
    }
}

//发送邮件
function do_send_email(id){
    swal({
        title: '是否发送邮件？',
        text: '邮件将发到对方邮箱',
        type: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: '确认！',
        cancelButtonText: '取消！',
    }).then(function(result){
        if (result.value) {
            //删除当前选择行
            ajax_request({url:"<?php echo $G_MODEL_URL;?>",type:"POST",dataType:"TEXT",data:{action:"send_email",id:id},access_token:"<?php echo $access_token?>"},function(result){
                var result = JSON.parse(result);
                result = result["rtval"];
                if(result=="done"){
                    //刷新数据
                    oTable.ajax.reload();
                    swal(
                        '发送成功!',
                        '邮件已发送',
                        'success'
                    );
                }else{
                    oTable.ajax.reload();
                    swal(
                        '发送失败!',
                        result,
                        'error'
                    );

                }
            })

        }
    })
}

// 订单查询按钮
$("[name='btn_poster_information_management_search']").on("click", function(e){
    do_order_search();
});


//右上角菜单按键
$(".mod_btn_<?php echo $G_MODEL_NAME; ?>").on("click", function(e){
    mod_fun_action($(this).attr("data-tap"));
    return;
});

// 海报管理
$('#<?php echo $G_MODEL_NAME; ?>_form').validate({
    submitHandler:function(form){
        //保存/修改
        var action = "";
        if($('[name="mod_poster_information_management_input_id"]').val()==""){
            //如果ID为空，新建一个记录
            action = "add";

        }else{
            //ID不为空，保存旧记录
            action = "edit";
        }
        ajax_request({url:"<?php echo $G_MODEL_URL;?>",type:"POST",dataType:"TEXT",data:{
                action:action,
                id:$('[name="mod_poster_information_management_input_id"]').val(),
                name:$('[name="mod_poster_information_management_input_name"]').val(),
                end_time:$('[name="mod_poster_information_management_input_end_time"]').val()
            },access_token:"<?php echo $access_token?>"},function(result){
            var result = JSON.parse(result);
            result = result["rtval"];
            if(result=="done"){
                //刷新数据
                oTable.ajax.reload();
                $('#dlg_<?php echo $G_MODEL_NAME; ?>_form').modal('hide');
            }else{
                swal("错误",result,"error");
            }
        })
        return false;
    },
    rules: {
        mod_poster_information_management_input_name: {
            required: true,
            minlength: 1
        },
        mod_poster_information_management_input_end_time: {
            required: true,
            minlength: 1
        }
    }
});


//创建右键菜单
function doDynamicMenu(idx, pos) {
    var $mymenu = $("<div class='mod_menu_<?php echo $G_MODEL_NAME; ?>'/>");
    $("body").append($mymenu);
    $.contextMenu({
        selector: '.mod_menu_<?php echo $G_MODEL_NAME; ?>',
        callback: function(key, options) {
            mod_fun_action(key);
        },
        items: {
            "add": {
                name: "添加",
                className: 'mod_menu_btn_<?php echo $G_MODEL_NAME; ?>_cps_poster_information_management_001'
            },
            "edit": {
                name: "修改",
                className: 'mod_menu_btn_<?php echo $G_MODEL_NAME; ?>_cps_poster_information_management_002'
            },
            "delete": {
                name: "删除",
                className: 'mod_menu_btn_<?php echo $G_MODEL_NAME; ?>_cps_poster_information_management_003'
            },
            "sep1": "---------",
            "refresh": {
                name: "刷新",
                className: 'mod_menu_btn_<?php echo $G_MODEL_NAME; ?>_cps_poster_information_management_004'
            }
        }

    });
    $(".mod_menu_<?php echo $G_MODEL_NAME; ?>").contextMenu(pos);
}

var oTable = $('#<?php echo $G_MODEL_NAME; ?>_list').DataTable({
    "ajax": {
        url:"<?php echo $G_MODEL_URL;?>",
        beforeSend: function (request) {
            request.setRequestHeader("access_token","<?php echo $access_token?>");
        },
        "dataSrc": function ( json ) {
            check_ajax_request(json);
            return json["rtval"]["data"];
        }
    },
    columns: [
        { data: 'id' },
        { data: 'name' },
        { data: 'status' },
        { data: 'number' },
        { data: 'start_time' },
        { data: 'end_time' }
    ],
    "deferRender": true,
    "iDisplayLength": 25,
    "ordering": true,
    "order": [0, 'desc'],
    "fnInitComplete": function() {
        //数据读取完成事件
    },
    columnDefs:[{
        targets: 2,
        render: function (data, type, row, meta) {
            var order_text = "";
            var order_class = "";
            switch(row["status"]) {
                case "proofreading":
                    order_text = "校稿中";
                    order_class = "text-success";
                    break;
                case "overtime":
                    order_text = "超过校稿时间";
                    order_class = "text-danger";
                    break;
                case "finish":
                    order_text = "已完成";
                    order_class = "text-info";
                    break;

            }
            return '<span class="'+order_class+'">'+order_text+'</span>';

        }
    },{
        targets: 3,
        render: function (data, type, row, meta) {
            return row["number"]+'/1';

        }
    },{
        targets: 6,
        render: function (data, type, row, meta) {
            return '<span class="label label-info" style="cursor:pointer" onclick="do_poster_upload(' + row["id"] + ',' + row["lock"] + ',' +  new Date(row["end_time"]).getTime()/1000 + ');"> 上传图片 </span>';
        }
    },{
        targets: 7,
        render: function (data, type, row, meta) {
            return '<span class="label label-info" style="cursor:pointer" onclick="do_poster_picture_department(' + row["id"]  + ',' + row["lock"] + ');"> 绑定部门 </span>';
        }
    },
        {
            targets: 8,
            render: function (data, type, row, meta) {
                return '<span class="label label-info" style="cursor:pointer" onclick="do_btn_upload(' + row["id"]  + ',' + row["lock"] + ');"> 导入按钮 </span>';
            }
        } ,
        {
            targets: 9,
            render: function (data, type, row, meta) {
                if(row["lock"] == "1"){
                    return '<span style="cursor:pointer"> <i class="fa fa-check"></i>已锁定 </span>';
                }else{
                    return '<span class="label label-info" style="cursor:pointer" onclick="do_poster_lock(' + row["id"]  + ');"> 锁定稿件 </span>';
                }

            }
        },{
            targets: 10,
            render: function (data, type, row, meta) {
                return '<span class="label label-info" style="cursor:pointer" onclick="do_poster_search(' + row["id"]  + ');"> 查看 </span>';
            }
        },{
            targets: 11,
            render: function (data, type, row, meta) {
                if(row[10] == "1"){
                    return '<span style="cursor:pointer"> <i class="fa fa-check"></i>已发送 </span>';
                }else{
                    return '<span class="label label-info" style="cursor:pointer" onclick="do_send_email(' + row["id"]  + ');"> 发送邮件 </span>';
                }

            }
        }],
    "oLanguage": {
        "sLengthMenu": "每页显示 _MENU_ 条记录",
        "sZeroRecords": "抱歉， 没有找到",
        "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
        "sInfoEmpty": "没有数据",
        "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
        "sZeroRecords": "没有检索到数据",
        "sSearch": "搜索:",
        "oPaginate": {
            "sFirst": "首页",
            "sPrevious": "前一页",
            "sNext": "后一页",
            "sLast": "尾页"
        }
    },
    "fnRowCallback": function(nRow) {

        $(nRow).on('mousedown',
            function(e) {
                if (e.button == 2) {
                    if ($(this).hasClass('selected')) {
                        //$(this).removeClass('selected');
                    } else {
                        oTable.$('tr.selected').removeClass('selected');
                        $(this).addClass('selected');
                    }

                    doDynamicMenu(0, {
                        x: e.clientX + document.documentElement.scrollLeft - document.documentElement.clientLeft + 5,
                        y: e.clientY + document.documentElement.scrollTop - document.documentElement.clientTop
                    });
                    return false;
                } else {

                    if ($(this).hasClass('selected')) {
                        //$(this).removeClass('selected');
                    } else {
                        oTable.$('tr.selected').removeClass('selected');
                        $(this).addClass('selected');
                    }
                }
                return true;
            });
    },
    dom: '<"html5buttons"B>lTfgitp',
    buttons: [{
        extend: 'copy'
    },
        {
            extend: 'csv'
        },
        {
            extend: 'excel',
            title: 'ExcelFile'
        },
        {
            extend: 'pdf',
            title: 'PDFFile'
        },

        {
            extend: 'print',
            customize: function(win) {
                $(win.document.body).addClass('white-bg');
                $(win.document.body).css('font-size', '10px');

                $(win.document.body).find('table').addClass('compact').css('font-size', 'inherit');
            }
        }]

});


// 判断如果需要
function trans_result_type(result,json_type=1){

}
